﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Media;
using System.Timers;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Spelprojekt
{
    class Player
    {
        public List<Projectile> projectiles = new List<Projectile>();
        public string PlayerPicture = "SpelareRight";
        public Rectangle pRec = new Rectangle(20, 300, 55, 90);
        protected bool ShootAble = true;
        public bool Tripleshoot = false;
        public bool Sprayshoot = false;
        private int toHeaven = -1;
        public int points = 0;
        public int life = 3;
        public int pLevel = 1;
        protected int Vel = 10;
        protected int walking = 4;
        public Player() { }
        public void Act()
        {
            KeyboardState KeyState = Keyboard.GetState();

            if (pLevel == 1 || pLevel == 2) 
                Vel = 10;
            else if (pLevel == 3)
                Vel = 20;
            else if (pLevel <= 4)
                Vel = 25;

#region Jump
            if (pRec.Y <= -2)
            {
                pRec.Y = -2;
            }
            else if (KeyState.IsKeyDown(Keys.W))
            {
                pRec.Y += -Vel;
                //using (var JumpsoundPlayer = new SoundPlayer(@"\\edunet\dfs\home09\ht12\johcah121\My Documents\Datavetenskap\Objektorienterad programmering\JohannesCarlsson\JohannesCarlsson\Spelprojekt\SpelprojektContent\Happyjump.wav"))
                //{
                //    JumpsoundPlayer.Play();
                //}
                
            }
            if (pRec.Y >= 395)
            {
                pRec.Y = 400;
            }
            else if (KeyState.IsKeyDown(Keys.S))
            {
                pRec.Y += Vel;
                //using (var JumpsoundPlayer = new SoundPlayer(@"\\edunet\dfs\home09\ht12\johcah121\My Documents\Datavetenskap\Objektorienterad programmering\JohannesCarlsson\JohannesCarlsson\Spelprojekt\SpelprojektContent\Happyjump.wav"))
                //{
                //    JumpsoundPlayer.Play();
                //}

            }
#endregion Jump

#region Walk 

            if (KeyState.IsKeyDown(Keys.D))
            {
                pRec.X += walking;
                //Banbytescroll framåt
                if (pRec.X >= 800)
                {
                    pRec.X = -55;
                }
            }

            if (KeyState.IsKeyDown(Keys.A))
            {
                pRec.X -= walking;
                //Banbytescroll bakåt
                if (pRec.X <= 0)
                {
                    pRec.X = 0;
                }
            }

#endregion Walk

#region Shoot

            if (KeyState.IsKeyDown(Keys.Space) && ShootAble)
            {
                Projectile proj1 = new Projectile(pRec, new Vector2(15, 0));
                projectiles.Add(proj1);
                if (Tripleshoot)
                {
                    Projectile proj2 = new Projectile(pRec, new Vector2(15, 3));
                    projectiles.Add(proj2);
                    Projectile proj3 = new Projectile(pRec, new Vector2(15, -3));
                    projectiles.Add(proj3);
                }
                ShootAble = false;
            }
            for (int i = 0; i < projectiles.Count(); i++)
            {
                projectiles[i].Move();
                if (projectiles[i].projRec.X > 771)
                {
                    projectiles.RemoveAt(i);
                }
            }
            if (KeyState.IsKeyUp(Keys.Space) || Sprayshoot)
                ShootAble = true;



        }

        public void killTripleshoot(object sender, ElapsedEventArgs e)
        {
            Tripleshoot = false;
        }

        public void killSprayshoot(object sender, ElapsedEventArgs e)
        {
            Sprayshoot = false;
        }
#endregion Shoot
        public void DropDead()
        {
            pRec.Y += toHeaven;
            PlayerPicture = "AngelPlayer";
            for (int i = 0; i < projectiles.Count(); i++)
            {
                projectiles[i].projRec.Y += pRec.Y;
            }

            if (pRec.Y < 200)
            {
                toHeaven--;
            }
            
        }

    }
}
